package com.fxp.project.jiuselu.web.models.userbank.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fxp.project.jiuselu.web.models.userbank.entity.JslUserBankCardInfo;
import com.fxp.project.jiuselu.web.models.userbank.mapper.JslUserBankCardInfoMapper;
import com.fxp.project.jiuselu.web.models.userbank.qo.BankCardSaveQo;
import com.fxp.project.jiuselu.web.models.userbank.service.IJslUserBankCardInfoService;
import com.fxp.project.jiuselu.web.models.userbank.vo.BankCardInfoVo;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Jason.Wang
 * @since 2022-01-09
 */
@Service
public class JslUserBankCardInfoServiceImpl extends ServiceImpl<JslUserBankCardInfoMapper, JslUserBankCardInfo> implements IJslUserBankCardInfoService {

    @Autowired
    private JslUserBankCardInfoMapper jslUserBankCardInfoMapper;

    @Override
    public void saveUserBankCard(BankCardSaveQo bankCardSaveQo, Long userId) {
        JslUserBankCardInfo cardInfo = new JslUserBankCardInfo();
        cardInfo.setCardNum(bankCardSaveQo.getCardNum());
        cardInfo.setBankName(bankCardSaveQo.getBankName());
        cardInfo.setBanSubBranchName(bankCardSaveQo.getBanSubBranchName());
        cardInfo.setCardUserName(bankCardSaveQo.getCardUserName());
        cardInfo.setCardUserIdcard(bankCardSaveQo.getCardUserIdcard());
        cardInfo.setCardUserPhone(bankCardSaveQo.getCardUserPhone());
        cardInfo.setUserId(userId);
        cardInfo.setCreateTime(LocalDateTime.now());
        cardInfo.setStatus(0);
        if (null!= bankCardSaveQo.getBankCardId()) {
            jslUserBankCardInfoMapper.update(cardInfo,new QueryWrapper<JslUserBankCardInfo>().eq("bank_card_id",bankCardSaveQo.getBankCardId()));
        } else {
            jslUserBankCardInfoMapper.insert(cardInfo);
        }
    }

    @Override
    public List<BankCardInfoVo> selectBankCardInfoListByUserId(Long userId) {
        return jslUserBankCardInfoMapper.selectBankCardInfoListByUserId(userId);
    }
}
